import Vue from 'vue'
import VueRouter from 'vue-router'
import HomeView from '../views/HomeView.vue'
import Footer from '../views/Footer.vue'
import Footer2 from '../views/Footer2.vue'

Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    name: 'home',
    components: {
      default: HomeView,
      footer: Footer
    }
  },
  {
    path:"/home",
    redirect:"/"
  },
  {
    path: '/square',
    name: 'square',
    components: {
      default: () => import(/* webpackChunkName: "square" */ '../views/Square.vue'),
      footer: Footer2
    }
  },
  {
    path: '/course',
    name: 'course',
    components: {
      default: () => import(/* webpackChunkName: "course" */ '../views/Course.vue'),
      footer: Footer
    }
  },
  {
    path: '/coursedeatil',
    name: 'courseDeatil',
    components: {
      default: () => import(/* webpackChunkName: "course" */ '../views/CourseDeatil.vue'),
      footer: Footer
    }
  },
  {
    path: '/system',
    name: 'system',
    component: () => import(/* webpackChunkName: "system" */ '../views/System.vue'),
    children: [{
      path: 'detail/:id',
      name: 'detail',
      component: () => import(/* webpackChunkName: "system" */ '../views/Detail.vue'),
      props: true,
      meta: { isKeep: true }
    }],
    // beforeEnter(to, from, next){
    //   // 单个路由内的守卫
    //   if(false){
    //     next();
    //   }else{
    //     next("/login")
    //   }
    // }
  }
]

const router = new VueRouter({
  routes
})

// 全局的路由守卫
// router.beforeEach((to, from, next)=>{
//   console.log(from, to);
//   // 注意进行全局的路由守卫时，要过滤调非验证路由，如：登录，首页
//   if(false || to.path === "/square"){
//     next()
//   }else{
//     next("/square");
//   }
// })

export default router
